package edu.biwu.filter;

import jakarta.servlet.*;

import java.io.IOException;

/**
 * 将一个类实现Filter接口,那么这个类就成为一个过滤器类
 */
public class FilterDemo01 implements Filter {
    @Override
    public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain filterChain) throws IOException, ServletException {
        System.out.println("FilterDemo01开始执行" + servletRequest + "..." + servletResponse);
        filterChain.doFilter(servletRequest, servletResponse);//一旦执行该方法，相当于过滤器放行，去访问目标资源
        System.out.println("FilterDemo01结束执行");

        servletResponse.setContentType("text/html;charset=UTF-8");
        servletResponse.getWriter().write("FilterDemo01的响应");
    }
}
